﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using DevComponents.DotNetBar.Controls;

namespace Quan_Ly_Nha_Thuoc
{
    public partial class frmMain
    {
        public frmMain()
        {
            InitializeComponent();
        }



        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btGioiThieu_Click(object sender, EventArgs e)
        {
            Form GT = new frmGioiThieu();
            GT.Show();
        }

        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            Form login = new frmDangNhap();
            login.Show();
        }

        #region Kiem Tra Tab đã xuất hiện trong TabCtrl_main chưa
        private bool checkTab(string TabName)
        {
            for (int i = 0; i < TabCtrl_main.Tabs.Count; i++)
            {
                if (TabCtrl_main.Tabs[i].Text == TabName)
                {
                    TabCtrl_main.SelectedTabIndex = i;
                    return true;
                }
            }
            return false;
        }
        #endregion

        private void btnNhomThuoc_Click(object sender, EventArgs e)
        {
            if (checkTab("Loại thuốc") == false)
            {
                TabItem tab = TabCtrl_main.CreateTab("Loại thuốc");

                frmLoaiThuoc form = new frmLoaiThuoc();
                form.Dock = DockStyle.Fill;
                form.FormBorderStyle = FormBorderStyle.None;
                form.TopLevel = false;
                tab.AttachedControl.Controls.Add(form);
                form.Show();
                TabCtrl_main.SelectedTabIndex = TabCtrl_main.Tabs.Count - 1;
            }
        }

        private void btDanhSachThuoc_Click(object sender, EventArgs e)
        {
            if (checkTab("Thuốc") == false)
            {
                TabItem tab = TabCtrl_main.CreateTab("Thuốc");

                frmThuoc form = new frmThuoc();
                form.Dock = DockStyle.Fill;
                form.FormBorderStyle = FormBorderStyle.None;
                form.TopLevel = false;
                tab.AttachedControl.Controls.Add(form);
                form.Show();
                TabCtrl_main.SelectedTabIndex = TabCtrl_main.Tabs.Count - 1;
            }
        }

        private void btnNhaSanXuat_Click(object sender, EventArgs e)
        {
            if (checkTab("Nhà Sản Xuất") == false)
            {
                TabItem tab = TabCtrl_main.CreateTab("Nhà Sản Xuất");

                frmNhaSanXuat form = new frmNhaSanXuat();
                form.Dock = DockStyle.Fill;
                form.FormBorderStyle = FormBorderStyle.None;
                form.TopLevel = false;
                tab.AttachedControl.Controls.Add(form);
                form.Show();
                TabCtrl_main.SelectedTabIndex = TabCtrl_main.Tabs.Count - 1;
            }
        }

        private void btnQuanLyKho_Click(object sender, EventArgs e)
        {
            if (checkTab("Quản Lý Kho") == false)
            {
                TabItem tab = TabCtrl_main.CreateTab("Quản Lý Kho");

                frmKho form = new frmKho();
                form.Dock = DockStyle.Fill;
                form.FormBorderStyle = FormBorderStyle.None;
                form.TopLevel = false;
                tab.AttachedControl.Controls.Add(form);
                form.Show();
                TabCtrl_main.SelectedTabIndex = TabCtrl_main.Tabs.Count - 1;
            }
        }

        private void btHoaDonNhap_Click(object sender, EventArgs e)
        {
            if (checkTab("Hoá đơn nhập") == false)
            {
                TabItem tab = TabCtrl_main.CreateTab("Hoá đơn nhập");

                frmHoaDonNhap form = new frmHoaDonNhap();
                form.Dock = DockStyle.Fill;
                form.FormBorderStyle = FormBorderStyle.None;
                form.TopLevel = false;
                tab.AttachedControl.Controls.Add(form);
                form.Show();
                TabCtrl_main.SelectedTabIndex = TabCtrl_main.Tabs.Count - 1;
            }
        }

        private void btHoaDonBan_Click(object sender, EventArgs e)
        {
            if (checkTab("Hoá đơn bán") == false)
            {
                TabItem tab = TabCtrl_main.CreateTab("Hoá đơn bán");

                frmHoaDonBan form = new frmHoaDonBan();
                form.Dock = DockStyle.Fill;
                form.FormBorderStyle = FormBorderStyle.None;
                form.TopLevel = false;
                tab.AttachedControl.Controls.Add(form);
                form.Show();
                TabCtrl_main.SelectedTabIndex = TabCtrl_main.Tabs.Count - 1;
            }

        }
    }
}
